package file;

import java.io.File;
import java.io.FileFilter;
/** 删除子项 */
public class DeleteFileDemo2 {
    public static void main(String[] args) {
        File file = new File(".");
        if (file.exists()){
            if (file.isDirectory()){
                FileFilter filter = new FileFilter() {//过滤器
                    @Override
                    public boolean accept(File file) {
                        String name = file.getName();
                        return name.endsWith(".txt");
                    }
                };
                File[] subs = file.listFiles(filter);
                System.out.println("当前项目目录下共有："+subs.length+"个子项");
                for (File sub : subs){
                    sub.delete();
                    System.out.println("文件已删除");
                }
            }
        }
    }
}
